<?php 
	class School_pages extends CI_Model{

	 	function __construct(){
        	parent::__construct();
    	}

		function update($id,$data){
			$this->db->where('id', $id);
 			return $this->db->update($this->table, $data);
		}

    	function get_list($limit = 0, $offset = 0, $data = 0){
			$where='status=1';
			if(!empty($data['search'])){
                $where .= " and page_title LIKE '%".$data['search']."%'";
            }

            if(!empty($data['school_id'])){
                $where .= " and school_id = '{$data['school_id']}'";
            }

            if(!empty($data['show_menu'])){
                $where .= " and show_menu = '1'";
            }
    		$sql = "SELECT SQL_CALC_FOUND_ROWS * FROM {$this->db->dbprefix}o2o_school_pages where $where ORDER BY sort,add_time desc ";
			if($offset){
				$sql .= " LIMIT ".$limit.",".$offset;
			}
    		$result = $this->db->query($sql)->result_array();
            $row_num =  $this->db->query('SELECT FOUND_ROWS() as row_num;')->row_array();
            return array("count" => $row_num['row_num'], "result" => $result);
    	}

        function batch_delete($ids){
            $ids = implode(",",$ids);
            $sql = "DELETE FROM {$this->db->dbprefix}".$this->table." WHERE id in($ids)";
            $this->db->query($sql);
        }

        function batch_cate_delete($ids){
            $ids = implode(",",$ids);
            $sql = "DELETE FROM {$this->db->dbprefix}".$this->cate_table." WHERE id in($ids)";
            $this->db->query($sql);
        }
    }